<?php

namespace App\Store\Validate\Order;

use App\Common\Validate\BaseValidate;

/**
 * 权限组验证器
 */
class OrderSales extends BaseValidate
{

    //验证规则
    protected $rule = [];
    //自定义验证信息
    protected $message = [];


    public function __construct($doaction = 'add')
    {
        if ($doaction == 'add') {
            $this->rule = [
                // 'mobile' => ['required', 'regex:/^1[3-9]\d{9}$/'],
                //'shopping_account_id1'=>'required_unless|is_maker:2',
                'shopping_account_id1'=>'required|integer|gt:0',
                // 'shopping_account_id2'=>'required|integer|gt:0',//非必填
                // 'classesset_id'=>'required|integer|gt:0',
                // 'order_at'=>'required',
                // 'issendpoints'=>'required|in:1,2',
                'pay_type_id'=>'required_if:is_maker,1',
                'goodslist'=>'required'
            ];
            $this->message = [
                'mobile.required' => '手机号码不能为空',
               /// 'mobile.regex'=>'手机号码不规范',
                'shopping_account_id1.required' => '导购未选择',
                'shopping_account_id1.integer' => '导购参数错误',
                'shopping_account_id1.gt' => '导购参数错误',
                // 'shopping_account_id2.required' => '副导购未选择',
                // 'shopping_account_id2.integer' => '副导购参数错误',
                // 'shopping_account_id2.gt' => '副导购参数错误',
//                'classesset_id.required' => '班次未选择',
//                'classesset_id.integer' => '班次参数错误',
//                'classesset_id.gt' => '班次参数错误',
                // 'order_at.required' => '下单时间未选择',
//                'issendpoints.required' => '是否产生积分未选择',
//                'issendpoints.in' => '是否产生积分参数错误',
                'goodslist.required' => '销售商品未选择',
                'pay_type_id.required_if' => '支付类型不能为空',
            ];
        } elseif ($doaction == 'edit') {
            $this->rule = [
                'id' => 'required|integer|gt:0',
                'shopping_account_id1'=>'required|integer|gt:0',
                'shopping_account_id2'=>'required|integer|gt:0',
                'classesset_id'=>'required|integer|gt:0',
                'order_at'=>'required',
                'imgpath' => 'required',
                'issendpoints'=>'required|in:1,2',
                'goodslist'=>'required'
            ];
            $this->message = [
                'id.required' => '参数错误',
                'id.integer' => '参数错误',
                'id.gt' => '参数错误',
                'shopping_account_id1.required' => '导购未选择',
                'shopping_account_id1.integer' => '导购参数错误',
                'shopping_account_id1.gt' => '导购参数错误',
                'shopping_account_id2.required' => '副导购未选择',
                'shopping_account_id2.integer' => '副导购参数错误',
                'shopping_account_id2.gt' => '副导购参数错误',
                'classesset_id.required' => '班次未选择',
                'classesset_id.integer' => '班次参数错误',
                'classesset_id.gt' => '班次参数错误',
                'order_at.required' => '下单时间未选择',
                'issendpoints.required' => '是否产生积分未选择',
                'issendpoints.in' => '是否产生积分参数错误',
                'goodslist.required' => '销售商品未选择',
            ];
        } elseif($doaction=='checkgoods'){
            $this->rule = [
                'goods_stock_id'=>'required|integer|gt:0',
                'count'=>'required|integer|gt:0',
                // 'weight'=>'required|gt:0',
                // 'price'=>'required|integer|gt:0',
                // 'total_money'=>'required|integer|gt:0',
            ];
            $this->message = [

                'goods_stock_id.required' => '销售商品未选择',
                'goods_stock_id.integer' => '销售商品参数错误',
                'goods_stock_id.gt' => '销售商品参数错误',
                'count.required' => '数量未选择',
                'count.integer' => '数量需为大于0的整数',
                'count.gt' => '数量需为大于0的整数',
            ];

        } elseif($doaction=='checksendgoods'){
            $this->rule=[
                'send_goods_stock_id'=>'required|integer|gt:0',
                'count'=>'required|integer|gt:0'
            ];
            $this->message = [

                'send_goods_stock_id.required' => '赠品未选择',
                'send_goods_stock_id.integer' => '赠品参数错误',
                'send_goods_stock_id.gt' => '赠品参数错误',
                'count.required' => '数量未选择',
                'count.integer' => '数量需为大于0的整数',
                'count.gt' => '数量需为大于0的整数',
            ];
        } elseif($doaction=='checkrecoverygoods'){
            $this->rule = [
                'change_type'=>'required|in:1,2',
                'recovery_type'=>'required|in:1,2',
                'goods_category_id'=>'required|integer|gt:0',
                'count'=>'required|integer|gt:0',
                // 'discount'=>'required|integer|gt:0',
                // 'dold_price'=>'required|integer|gte:0',
                'money'=>'required',
            ];
            $this->message = [
                'change_type.required' => '换货方式未选择',
                'change_type.in' => '换货方式参数错误',
                'recovery_type.required' => '回收方式未选择',
                'recovery_type.in' => '回收方式参数错误',
                'goods_category_id.required' => '旧料类别未选择',
                'goods_category_id.integer' => '旧料类别参数错误',
                'goods_category_id.gt' => '旧料类别参数错误',
                'count.required' => '数量不能为空',
                'count.integer' => '数量需大于0',
                'count.gt' => '数量需大于0',
                // 'discount.required' => '折扣不能为空',
                // 'discount.integer' => '折扣参数错误',
                // 'discount.gt' => '折扣参数错误',
                // 'dold_price.required' => '折旧单价不能为空',
                // 'dold_price.integer' => '折旧单价参数错误',
                // 'dold_price.gte' => '折旧单价参数错误',
                'money.required' => '金额不能为空',
            ];
        } elseif($doaction=='checkmember'){
            $this->rule = [
                'id'=>'required|integer|gt:0',
               // 'mobile' => ['required', 'regex:/^1[3-9]\d{9}$/'],
                'mobile'=>'required'
            ];
            $this->message = [
                'id.required' => '订单参数错误',
                'id.integer' => '订单参数错误',
                'id.gt' => '订单参数错误',
                'mobile.required' => '手机号码不能为空',
              //  'mobile.regex'=>'手机号码不规范',
            ];

        }
    }
}
